package com.mew.chess.core.game.pokdeng.game.message;

import com.mew.chess.core.game.pokdeng.game.PokDengSeatManager;
import com.zebra.common.ByteBufUtils;
import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author dylin
 * @create 2021/4/29
 */
@Data
@ToString
@NoArgsConstructor
public class EnterResponse extends ZebraBaseMessage<EnterResponse> {

    private UserMessage userMessage;
    private int[] roomBetArray;
    private long lastBetNumber; // 上把 押注

    private long ino;//局号
    private int tableId;//桌子号
    private int seatNo;//座位号
    private int startSeat;//开始座位

    private PokDengSeatManager banker;//庄家牌
    private Collection<PokDengSeatManager> seats;

    private int linkType;
    private int remainTime;

    @Override
    public void write(ByteBuf b) {

        userMessage.write(b);
        writeIntArray(b, this.roomBetArray);
        writeLong(b, this.lastBetNumber);
        writeLong(b, this.ino);
        writeInt(b, this.tableId);
        writeInt(b, this.seatNo);
        writeInt(b,startSeat);
        banker.write(b);
        writeInt(b,seats.size());
        for (PokDengSeatManager seat : seats) {
            seat.write(b);
        }
        writeInt(b, this.linkType);
        writeInt(b, this.remainTime);

    }

    @Override
    public EnterResponse read(ByteBuf b) {
        EnterResponse message =new EnterResponse();
        UserMessage userMessage = new UserMessage();
        userMessage.read(b);
        message.setUserMessage(userMessage);
        message.roomBetArray = readIntArray(b);
        message.lastBetNumber = readLong(b);
        message.linkType = readInt(b);
        message.remainTime = readInt(b);

        return message;
    }
}
